--[[
@module export
@usage: export layername filepath
]]
local lume = require(LIB_PATH.."lume")
local Command = require "command"
return Command("export", {

	{ "layer", function (layer, to)
		local name = layer or Sled.current_layer.name
		if layer == "current" then name = Sled.current_layer.name end
		local filename = to or name
		local lay = Sled.current_map.layers:get(name)
		if not lay then return name .. " is not a layer"
		else lay:export(filename) end
		return string.format("Layer %s exported to %s", name, filename)
	end },
	
	{ "tile", function (to)
		local filename = to or "untitled"
		local tile = Sled.current_tile or Tile(1, 1):select()
		tile:export(filename)
	end },
	
	{ "map", function (name, to)
			local map
			if not name then map = Sled.current_map
			else
				map = lume.match(Sled.maps, function (v)
					return v.name == name
				end)
				if not map then return "map " .. name .. " not found" end
			end
			local filename = to or map.name
			map:export(filename)
			return map.name .. " exported to: ".. filename..".map"
		end,
	}

})
